/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-11-06 11:33:12
 * @FilePath: \corpus\src\pages\resourceManagement\list\component\ExportFile\index.tsx
 */
import UploadCorpusMuplte from '@/components/UploadCorpusMuplte';
import { useLocation } from '@umijs/max';
import { Form, Modal } from 'antd';
import type React from 'react';
import { useEffect } from 'react';
import hooks from '../../hooks';
const EditAngent: React.FC = () => {
  const {
    setExportFileVisible,
    addResourceFileContent,
    exportFileVisible,
    exportFile,
    setNewList,
  } = hooks.useContainer();

  const location: Record<string, any> = useLocation();

  const val = location?.state?.val ? location?.state?.val : '';
  const title = '批量导入';

  const handleSubmit = () => {
    exportFile.validateFields().then((vals) => {
      const method = addResourceFileContent;
      method.run({
        ...vals,
      });
    });
  };

  useEffect(() => {
    if (!exportFileVisible) {
      setNewList([]);
      exportFile.resetFields();
    }
  }, [exportFileVisible]);
  return (
    <Modal
      width={600}
      title={title}
      open={exportFileVisible}
      onCancel={() => {
        exportFile.resetFields();
        setExportFileVisible(false);
      }}
      onOk={handleSubmit}
      confirmLoading={addResourceFileContent.loading}
    >
      <Form labelCol={{ span: 4 }} form={exportFile}>
        <Form.Item name="id" hidden />

        <Form.Item label={`上传`} name="files" rules={[{ required: true, message: '请选择' }]}>
          <UploadCorpusMuplte
            action="/corpus/common/filesUpdate"
            multiple={true}
            handleChange={({ fileList }) => {
              console.log(fileList);
              const arr = fileList.map((item) => {
                return { ...item.response?.data[0] };
              });
              exportFile.setFieldValue('files', arr);
              console.log(arr);
            }}
          />
        </Form.Item>
        <Form.Item label={''} name="" rules={[{ required: false, message: '请选择' }]}>
          <p style={{ padding: '10.0px', color: 'gray' }}>
            批量上传总数不超过100个，累计大小不超过1.5G
          </p>
          <p style={{ padding: '5.0px 10.0px', color: 'gray' }}>
            参考<a>JSONL模板</a>上传语料，支持将JSONL格式语料生成知识。
          </p>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default EditAngent;
